package leetcode;

/**
 * 寻找数组的中心索引
 */
public class LeetCode724 {
    public int pivotIndex(int[] nums) {
        int sum = getSum(nums);
        int leftSum = 0;
        for (int i = 0; i < nums.length; i++) {
            if (2 * leftSum + nums [i] == sum) return i;
            leftSum += nums[i];
        }
        return -1;
    }

    public int getSum(int[] nums){
        int sum = 0;
        for (int i = 0; i < nums.length; i++){
            sum += nums[i];
        }
        return sum;
    }
}